home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr05 / xnot12a.zip / XIO.C < prev    next >
C/C++ Source or Header  |  1993-06-11  |  8KB  |  410 lines

  1. #ifdef X11 /** WHOLE FILE **/  
  2. #include "jam.h"
  3.   
  4. /*
  5.  * X11 interface
  6.  */
  7. #include    "def.h"
  8.   
  9. int    tceeol = 0  /* 2 */;
  10. int    tcinsl = 2  /* 5 */;
  11. int    tcdell = 2  /* 5 */;
  12.  
  13. static int insdel = TRUE;    /* Do we have both insert & delete line? */
  14. static int bioscol = -1;        /* cursor column */
  15. static int curcolor = -1;
  16.  
  17. static void rn_(WindowMoveLines,(int row, int bot, int num, int up));
  18. static void rn_(putthechar,(unsigned char  c));
  19.  
  20. /* erase window content with clipping
  21.  */
  22. void WindowErase()
  23. {
  24.   RECT rect;
  25.  
  26.   if (edInited)
  27.     {
  28.       rect.left = rect.top = 0;
  29.       rect.right = WinWidth();
  30.       rect.bottom = WinHeight();
  31.       ZapRect(&rect);
  32.     }
  33. }
  34.  
  35. /*
  36.  * Initialize the terminal when the editor
  37.  * gets started up.
  38.  */
  39. ttinit() 
  40. {
  41.   return TRUE;
  42. }
  43.  
  44. /*
  45.  * Clean up the terminal, in anticipation of
  46.  * a return to the command interpreter.
  47.  */
  48. tttidy() 
  49. {
  50.   return TRUE;
  51. }
  52.  
  53. /*
  54.  * Move the cursor to the specified
  55.  * origin 0 row and column position.
  56.  */
  57. ttmove(row, col) 
  58. int row, col;
  59. {
  60.   ttcol = col;
  61.   ttrow = row;
  62.   g_caret_x = (col * g_nCharWidth) + FudgeEdge;
  63.   g_caret_y = (row * g_nLineHeight);
  64.   bioscol = col;  
  65.   return TRUE;
  66. }
  67.  
  68. /*
  69.  * Erase to end of page.
  70.  */
  71. tteeop() 
  72. {
  73.   if (edInited)
  74.     WindowZapLines(ttrow, nrow);
  75.   return TRUE;
  76. }
  77.  
  78. void WindowZapLines(row, bot)
  79. int row, bot;
  80. {  
  81.   RECT rect;
  82.  
  83.   rect.left = 0;  
  84.   rect.right = WinWidth();
  85.   rect.top = row * g_nLineHeight;
  86.   rect.bottom = ((bot + 1) * g_nLineHeight) - 1;
  87.   ZapRect(&rect);
  88. }
  89.  
  90. /*
  91.  * Insert nchunk blank line(s) onto the
  92.  * screen, scrolling the last line on the
  93.  * screen off the bottom.
  94.  */
  95. ttinsl(row, bot, nchunk) 
  96. int row, bot, nchunk;
  97. {
  98.   if (row == bot) 
  99.     {                            /* Case of one line insert is     */
  100.       ttmove(row, 0);        /*    special            */
  101.       tteeol();
  102.     }
  103.   else
  104.     WindowMoveLines(row, bot, nchunk, FALSE);
  105.   return TRUE;
  106. }
  107.  
  108. /*
  109.  * Delete nchunk line(s) from "row", replacing the
  110.  * bottom line on the screen with a blank line. 
  111.  */
  112. ttdell(row, bot, nchunk)
  113. int row, bot, nchunk;
  114. {
  115.   if (row == bot)
  116.     {                         /* One line special case    */
  117.       ttmove(row, 0);
  118.       tteeol();
  119.     }
  120.   else
  121.     WindowMoveLines(row, bot, nchunk, TRUE);
  122.   return TRUE;
  123. }
  124.  
  125. /*
  126.  * Switch to full screen scroll. This is
  127.  * used by "spawn.c" just before is suspends the
  128.  * editor, and by "display.c" when it is getting ready
  129.  * to exit.
  130.  */
  131. ttnowindow()
  132. {
  133.   return TRUE;
  134. }
  135.  
  136. /*
  137.  * Set the current writing color to the
  138.  * specified color. Watch for color changes that are
  139.  * not going to do anything (the color is already right)
  140.  * and don't send anything to the display.
  141.  */
  142. ttcolor(color) 
  143. register int color; 
  144. {
  145.   if (curcolor != color)
  146.     curcolor = color;
  147.   tthue = color;           /* Save the color.    */
  148.   return TRUE;
  149. }
  150.  
  151. /*
  152.  * This routine is called by the
  153.  * "refresh the screen" command to try and resize
  154.  * the display. The new size, which must be deadstopped
  155.  * to not exceed the NROW and NCOL limits, it stored
  156.  * back into "nrow" and "ncol". Display can always deal
  157.  * with a screen NROW by NCOL. Look in "window.c" to
  158.  * see how the caller deals with a change.
  159.  */
  160. ttresize() 
  161. {
  162.   int flag = 0;
  163.   
  164.   setttysize();
  165.   if (nrow > NROW)
  166.     flag = nrow = NROW;
  167.   if (ncol > NCOL)
  168.     flag = ncol = NCOL;
  169.   
  170.   /* non-zero means reached a limit
  171.    */
  172.   if (flag)
  173.     ewprintf("Internal limit: max rows/cols reached.");
  174.   return TRUE;
  175. }
  176. ttputc(c)
  177. unsigned char c;
  178. {
  179.   if (c == '\b') 
  180.     {
  181.       if (bioscol-1 > 0) 
  182.     {
  183.       ttmove(ttrow, bioscol-1);
  184.     }
  185.       return(1);
  186.     }
  187.   else if (c == '\r') 
  188.     {
  189.       ttmove(ttrow, 0);
  190.       return(1);
  191.     }
  192.   
  193.   if (edInited)
  194.     putthechar(c);
  195.   
  196.   if (bioscol+1 >= ncol)
  197.     ttmove(ttrow + 1, 0);
  198.   else
  199.     ttmove(ttrow, bioscol + 1);
  200.   return(TRUE);
  201. }
  202.  
  203. /*
  204.  * Erase to end of line.
  205.  */
  206. tteeol() 
  207. {
  208.   RECT rect;
  209.   
  210.   if (edInited)
  211.     {
  212.       rect.top = g_caret_y;
  213.       rect.left = g_caret_x;
  214.       rect.right = WinWidth();
  215.       rect.bottom = rect.top + g_nLineHeight;
  216.       ZapRect(&rect);
  217.     }
  218.   return TRUE;
  219. }
  220.  
  221. /*
  222.  * Make a noise.
  223.  */
  224. ttbeep() 
  225. {
  226.   ringbell();
  227.   return TRUE;
  228. }
  229.  
  230. /* insert/delete num lines at row
  231.  */
  232. static void WindowMoveLines(row, bot, num, up)
  233. int row, bot, num, up;
  234. {
  235.   RECT scrollrect;
  236.   int dest_y, line, direction;
  237.   int width, height;
  238.   
  239.   /* Comnpute block to 'scroll'
  240.    */
  241.   scrollrect.left = 0;
  242.   scrollrect.right = WinWidth();
  243.   scrollrect.top = row * g_nLineHeight;
  244.   scrollrect.bottom = (bot + 1) * g_nLineHeight;
  245.  
  246.   /* Calc size, destination
  247.   */
  248.   if (up)
  249.     {
  250.       direction = -1; 
  251.       line = bot;
  252.     }
  253.   else
  254.     {
  255.       direction = 1;
  256.       line = row;
  257.     }
  258.   width = scrollrect.right;
  259.   height = scrollrect.bottom - scrollrect.top;  
  260.   dest_y = scrollrect.top + ((num * g_nLineHeight) * direction); 
  261.  
  262.   /* Clip to scroll area
  263.   */
  264.   NewClipping(scrollrect.left, scrollrect.top, width, height);
  265.   XCopyArea(gDpy, gWindow, gWindow, gText, scrollrect.left, scrollrect.top,
  266.             (unsigned int)width, (unsigned int )height, scrollrect.left, 
  267.             dest_y);
  268.  
  269.   /* erase 'moved' lines
  270.   */
  271.   if (up)
  272.     scrollrect.top = dest_y + (scrollrect.bottom - scrollrect.top);
  273.   else
  274.     scrollrect.bottom = dest_y;
  275.   ZapRect(&scrollrect);
  276.   NoClipping();
  277.  
  278.   WindowZapLines(line, line);  /* zap the special target */
  279. }
  280.  
  281. /* Dump char to window at current position. Semi optimized by collecting
  282. * consecutives chars to a string for output.
  283.  */
  284. #define LINESIZE (NCOL + 2)
  285. static char theLine[LINESIZE];
  286. static int theX, theY;
  287. static int theColor;
  288. static int theIndex = 0;
  289.  
  290. static void putthechar(c)
  291. unsigned char c;
  292. {
  293.   /* Flush text if buffer fills, color changes or position
  294.   * of new char is not directly following last char, on same line.
  295.   */
  296.   if ((theIndex + 1) >= LINESIZE)
  297.     ttcharflush();
  298.   else if (curcolor != theColor)
  299.     ttcharflush();
  300.   else if ((theX + (theIndex * g_nCharWidth)) != g_caret_x)
  301.     ttcharflush();
  302.   else if (theY != g_caret_y)
  303.     ttcharflush();
  304.   
  305.   /* Add new char to string.
  306.   */
  307.   if (theIndex == 0)    /* Save the start position, etc of new line */
  308.     {
  309.       theColor = curcolor;
  310.       theX = g_caret_x;
  311.       theY = g_caret_y;
  312.     }
  313.   theLine[theIndex++] = (char)c;
  314.   theLine[theIndex] = '\0';
  315. }
  316. /* Dump a string to current position.
  317. */
  318. int ttputline(text)
  319. char *text;
  320. {
  321.   XDrawImageString(gDpy, gWindow, 
  322.                    (curcolor == CTEXT ? gText : 
  323.                     (curcolor == CHIGH ? gTouchedText :gMode)), 
  324.                g_caret_x, yCharPos(g_caret_y), text, (int)strlen(text));
  325.   return(TRUE);
  326. }
  327.  
  328. /* Flush any output, clear the string
  329. */
  330. void ttcharflush()
  331. {
  332.   if (theIndex >= 1)
  333.     {
  334.       XDrawImageString(gDpy, gWindow, 
  335.                        (theColor== CTEXT ? gText : 
  336.                         (theColor == CHIGH ? gTouchedText :gMode)), 
  337.                    theX, yCharPos(theY), theLine, (int)strlen(theLine));
  338.       theLine[0] = '\0';
  339.       theIndex = 0;
  340.     }
  341. }
  342.  
  343. ttwait()
  344. {
  345.   return(0);
  346. }
  347.  
  348. /* erase a given rect
  349.  */
  350. void ZapRect(rect)
  351. RECT *rect;
  352. {
  353.   XFillRectangle(gDpy, gWindow, gMode, 
  354.          rect->left, rect->top, 
  355.                  (unsigned int )(rect->right - rect->left), 
  356.          (unsigned int )(rect->bottom - rect->top));
  357. }
  358.  
  359. /* query for window size and convert it to
  360.  * rows and cols based on current font info
  361.  */
  362. void WindowGetSize(nrow, ncol)
  363. int *nrow, *ncol;
  364. {
  365.   XWindowAttributes atts;
  366.  
  367.   XGetWindowAttributes(gDpy, gWindow, &atts);
  368.   *ncol = (atts.width - (2 * FudgeEdge))/g_nCharWidth;
  369.   *nrow = atts.height/g_nLineHeight;
  370. }
  371. void WindowNewSize(row,col)
  372. int row, col;
  373. {
  374.   SizeWindow(0,0, col, row);
  375. }
  376. /* size the window based on current font and resources
  377. * for cols, lines - basically a noop
  378. */
  379. void InitSizeWindow(numcols, numlines)
  380. int numcols, numlines;
  381. {
  382.   SizeWindow(0, 0, numcols, numlines); 
  383. }
  384.  
  385. /* (re)size the window based on cols & rows
  386.  */
  387. void SizeWindow(x, y, cols, lines)
  388. int x, y, cols, lines;
  389. {
  390.   unsigned int mask;
  391.   XWindowChanges values;
  392.  
  393.   values.width = (cols * g_nCharWidth) + (2 * FudgeEdge);
  394.   values.height = (lines * g_nLineHeight);
  395.   mask = CWWidth | CWHeight;
  396.   XConfigureWindow(gDpy, gWindow, mask, &values);
  397.   XSync(gDpy, 0);
  398. }
  399.  
  400. /* Draw marker based on cursor location;must be xor!
  401.  */
  402. void DrawMarker()
  403. {
  404.   XFillRectangle(gDpy, gWindow, gXor, g_caret_x, yCharPos(g_caret_y), 
  405.                  (unsigned int)g_nCharWidth, 
  406.                  (unsigned int)(g_nLineHeight - FudgeHeight));
  407. }
  408. #endif /* WHOLE FILE */
  409.  
  410.